<template>
  <div class="home-container">
    <van-nav-bar class="page-nav-bar" fixed>
      <div class="logo" slot="left"></div>

      <van-button
        class="search-btn"
        slot="right"
        type="info"
        size="small"
        round
        icon="search"
        to="/search"
        >搜索</van-button
      >
    </van-nav-bar>

    <!-- 频道列表 -->
    <div class="channel-list">
      <van-tabs v-model="active" class="channel-tabs " animated swipeable>
        <van-tab v-for="item in myChannels" :key="item.id" :title="item.name">
          <article-list
            :id="item.id"
            :refname="'artlist' + item.id"
          ></article-list>
        </van-tab>

        <div slot="nav-right" class="placeholder"></div>
        <div slot="nav-right" class="hamburger-btn" @click="popupEditFn">
          <i class="iconfont icon-gengduo"></i>
        </div>
      </van-tabs>
    </div>

    <!-- 频道编辑 -->
    <van-popup
      class="edit-channel-popup"
      v-model="showEditPop"
      closeable
      round
      position="bottom"
      :style="{ height: '90%' }"
    >
      <!-- 频道编辑 -->
      <channel-edit
        v-if="showEditPop"
        :myChannels="myChannels"
        :active="active"
        @update-active="updateActiveFn"
      />
    </van-popup>
  </div>
</template>

<script>
import { getUserChannelsAPI } from '@/api'
import ArticleList from '@/components/article/article-list.vue'
import ChannelEdit from './components/channel-edit.vue'
export default {
  name: 'HomeIndex',
  props: {},
  components: { ArticleList, ChannelEdit },
  computed: {},
  created () {
    this.getUserChannels()
  },
  mounted () {},
  watch: {},
  data () {
    return {
      active: 0,
      myChannels: [],
      showEditPop: false // 频道编辑
    }
  },
  methods: {
    async getUserChannels () {
      const { data: res } = await getUserChannelsAPI()
      // console.log(res)
      this.myChannels = res.data.channels
    },
    popupEditFn () {
      this.showEditPop = true
    },
    // 编辑渠道时点击我的频道，
    updateActiveFn (act, flag) {
      this.active = act
      this.showEditPop = flag
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  padding-bottom: 100px;
  padding-top: 180px;
  .logo {
    width: 200px;
    height: 100%;
    background: url('~@/assets/logo.png') no-repeat left;
    background-size: 100%;
  }
  /deep/ .van-nav-bar__right {
    max-width: unset; // 属性取消

    .search-btn {
      width: 400px;
      height: 64px;
      background-color: #55a7ff;
      border: none;
      font-size: 28px;
      .van-icon {
        font-size: 32px;
      }
    }
  }

  // 2.tab栏 ---------------------------------
  /deep/ .channel-tabs {
    .van-tab {
      border-right: 1px solid #edeff3;
      min-width: 200px;
      font-size: 30px;
    }

    .van-tab--active {
      color: #333333;
    }

    .van-tabs__nav {
      padding-bottom: 0;
    }

    .van-tabs__line {
      bottom: 8px;
      width: 31px !important;
      height: 6px;
      background-color: #3296fa;
    }

    .van-tabs__wrap {
      position: fixed;
      left: 0;
      top: 92px;
      z-index: 2;
      width: 100%;
    }
    .placeholder {
      //元素不参与flex 布局的宽度分配
      flex-shrink: 0;
      width: 100px;
      height: 82px;
    }
    .hamburger-btn {
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 66px;
      height: 82px;
      background-color: #fff;
      opacity: 0.902;
      i.iconfont {
        font-size: 33px;
      }
      &::before {
        content: '';
        position: absolute;
        left: 0;
        width: 1px;
        height: 100%;
        background-image: url(~@/assets/gradient-gray-line.png);
        background-size: contain;
      }
    }
  }
}
</style>
